using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MyShareSpace : MonoBehaviour
{
    [SerializeField] private Button btnStart;
    [SerializeField] private Button btnStop;
    [SerializeField] private Button btnReset;
    [SerializeField] private Animator AniConveyor;
    [SerializeField] private Animator AniSensorA;
    [SerializeField] private Animator AniSensorB;
    void Start()
    {
        btnStop.onClick.AddListener(() =>
        {
            // Debug.Log("hello");
            // AniConveyor.speed = 1; 
        });

    }
    public void ToggleByClick()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit nowHit))
        {
            if (nowHit.transform.parent.gameObject.TryGetComponent<Animator>(out Animator ani))
            {
                ani.SetBool("isOn", !ani.GetBool("isOn"));
                if (ani.name == "conveyor0" || ani.name == "spinTool")
                {
                    ani.speed = ani.speed > 0 ? 0 : 1;
                }
            }
        }
    }
    public void ConveyorCtrl()
    {
        if (!AniSensorA.GetBool("isOn") &&
        AniSensorA.GetBool("isBack") &&
        !AniSensorB.GetBool("isOn") &&
        AniSensorB.GetBool("isBack"))
        {
            ConveyorSpeedCtl(true);
        }
    }
    public void ConveyorSpeedCtl(bool isOn)
    {
        AniConveyor.speed = isOn ? 1 : 0;
    }
    public void ColorStartCtl(bool isOn)
    {
        btnStart.image.color = isOn ? Color.green : Color.white;
    }
    public void ColorStopCtl(bool isOn)
    {
        btnStop.image.color = isOn ? Color.red : Color.white;
    }
    public void ColorResetCtl(bool isOn)
    {
        btnReset.image.color = isOn ? Color.yellow : Color.white;
    }

    void Update()
    {

    }
}
